package com.xx.dao;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.xx.entity.Project;
import com.xx.util.DBHelp;
import com.xx.util.RowMapper;

public class ProjectDao {
DBHelp<Project>   db=new DBHelp<Project>();
public List<Project> findProjects(String id){
	
	String sql ="SELECT id,NAME,`desc`,createtime FROM t_project WHERE id IN(SELECT projectid FROM t_employee_project WHERE employeeid =? )";
	return db.executeQueryForList(sql, new ProdjectMapper(),id);
	
	
}
public void  insert(Project project) {
	String sql="insert into t_project(id,NAME,`desc`,createtime) value(?,?,?,?)";
	db.executeSQL(sql, project.getId(),project.getName(),project.getDesc(),project.getCreatetime());
}





public class ProdjectMapper implements RowMapper<Project>{

	public Project mapperRow(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
	            Project project=new Project();
	    project.setId(rs.getString("id"));
	    project.setName(rs.getString("name"));
	    project.setDesc(rs.getString("desc"));
	    project.setCreatetime(rs.getString("createtime"));
	         return project;
	} 

}





public Project  findProjectByid(String id) {
	// TODO Auto-generated method stub
	String sql ="SELECT id,NAME,`desc`,createtime FROM t_project WHERE id =?";
	return db.executeQueryForObject(sql, new ProdjectMapper(),id);
}

}
